Socket
Socket
Sign inDemoInstall

io-ts-reporters

Package Overview
Dependencies
2
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    io-ts-reporters

Formatting of io-ts validation errors


Version published
Weekly downloads
202K
increased by5.33%
Maintainers
2
Install size
24.6 kB
Created
Weekly downloads
 

Readme

Source

io-ts-reporters

Error reporters for io-ts.

Currently this package only includes one reporter. The output is an array of strings in the format of:

Expecting ${expectedType} at ${path} but instead got: ${expectedType}

And for union types:

Expecting one of:
    ${unionType1}
    ${unionType2}
    ${...}
    ${unionTypeN}
at ${path} but instead got: ${actualValue}

Installation

yarn add io-ts-reporters

Example

import * as t from 'io-ts';
import reporter from 'io-ts-reporters';

const User = t.interface({ name: t.string });

// When decoding fails, the errors are reported
reporter.report(User.decode({ nam: 'Jane' }));
//=> ['Expecting string at name but instead got: undefined']

// Nothing gets reported on success
reporter.report(User.decode({ name: 'Jane' }));
//=> []

To only format the validation errors in case the validation failed (ie. mapLeft) use formatValidationErrors instead.

import * as t from 'io-ts';
import { formatValidationErrors } from 'io-ts-reporters';
import * as E from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';

const User = t.interface({ name: t.string });

const result = User.decode({ nam: 'Jane' }); // Either<t.Errors, User>

E.mapLeft(formatValidationErrors)(result); // Either<string[], User>

For more examples see the tests.

TypeScript compatibility

io-ts-reporters versionrequired typescript version
1.0.03.5+
<= 0.0.212.7+

Testing

yarn
yarn run test

Credits

This library was created by OliverJAsh.

Keywords

FAQs

Last updated on 21 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc